package com.nwpu.coursesupport.service.imple;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nwpu.coursesupport.entity.Task;
import com.nwpu.coursesupport.entity.bean.JSONResult;
import com.nwpu.coursesupport.mapper.TaskMapper;
import com.nwpu.coursesupport.view.TaskAssignView;
import com.nwpu.coursesupport.view.criteria.TaskAssignViewSearchCriteria;
import com.nwpu.coursesupport.view.mapper.TaskAssignViewMapper;

@Service
public class TaskAssignViewService {

	@Autowired
	private TaskAssignViewMapper taskAssignViewMapper;
	@Autowired
	private TaskMapper taskMapper;
	
    protected static Logger logger = LoggerFactory.getLogger(TaskAssignViewService.class);

	
	public JSONResult getTaskMainAssignView(TaskAssignViewSearchCriteria sc){
		JSONResult rst=new JSONResult();
		rst.fail();
		
		if(sc==null||sc.getTaskId()<=0){
			logger.error("参数错误");
			return rst.fail("参数错误");
		}
		Task task=this.taskMapper.findById(sc.getTaskId());
		if(task==null){
			logger.error("该任务不存在");
			return rst.fail("该任务不存在");
		}
		List<TaskAssignView> list=this.taskAssignViewMapper.getTaskMainAssignView(sc);
		rst.addData("list", list);
		rst.addData("courseId", task.getCourseId());
		rst.addData("taskId",task.getId());
		rst.success();
		return rst;
	}
	
	public JSONResult getTaskInLessonAssignView(TaskAssignViewSearchCriteria sc){
		JSONResult rst=new JSONResult();
		rst.fail();
		
		if(sc==null||sc.getTaskId()<=0){
			logger.error("参数错误");
			return rst.fail("参数错误");
		}
		Task task=this.taskMapper.findById(sc.getTaskId());
		if(task==null){
			logger.error("该任务不存在");
			return rst.fail("该任务不存在");
		}
		
		List<TaskAssignView> list=this.taskAssignViewMapper.getTaskInLessonAssignView(sc);
		rst.addData("list", list);
		rst.addData("courseId", task.getCourseId());
		rst.addData("taskId",task.getId());
		rst.success();
		return rst;
	}
}
